//------------Sonic CD Mosqui Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 36: TYPE_MOSQUI


sub ObjectMain
	if Object.PropertyValue==0
		switch Object.State
		case 0
			Object.Priority=1
			Object.Frame++
			Object.Frame&=3
			Object.XPos-=65536
			Object.Value0--
			if Object.Value0==-128
				Object.State=1
				Object.Direction=FACING_LEFT
			endif
			if Player.YPos>Object.YPos
				TempValue0=Player.YPos
				TempValue0-=Object.YPos
				if TempValue0<8388608
					if Player.XPos>Object.XPos
						TempValue0=Player.XPos
						TempValue0-=Object.XPos
					else
						TempValue0=Object.XPos
						TempValue0-=Player.XPos
					endif
					if TempValue0<3145728
						Object.Value0=0
						Object.Frame=2
						Object.State=2
					endif
				endif
			endif
			break
		case 1
			Object.Frame++
			Object.Frame&=3
			Object.XPos+=65536
			Object.Value0++
			if Object.Value0==128
				Object.State=0
				Object.Direction=FACING_RIGHT
			endif
			if Player.YPos>Object.YPos
				TempValue0=Player.YPos
				TempValue0-=Object.YPos
				if TempValue0<8388608
					if Player.XPos>Object.XPos
						TempValue0=Player.XPos
						TempValue0-=Object.XPos
					else
						TempValue0=Object.XPos
						TempValue0-=Player.XPos
					endif
					if TempValue0<3145728
						Object.Value0=0
						Object.Frame=2
						Object.State=2
					endif
				endif
			endif
			break
		case 2
			Object.Value0++
			if Object.Value0==8
				Object.Value0=0
				Object.Frame++
				if Object.Frame==5
					Object.Frame=4
					Object.State=3
				endif
			endif
			break
		case 3
			Object.YPos+=393216
			ObjectTileCollision(0,0,14,0)
			if CheckResult==1
				Object.State=4
				PlayStageSfx(2,0)
			endif
			break
		case 4
			break
		case 5
			if Object.OutOfBounds==1
				Object.State=0
				Object.Direction=FACING_RIGHT
				Object.Priority=0
			endif
			break

		endswitch
	else
		switch Object.State
		case 0
			Object.Priority=1
			Object.Frame++
			Object.Frame%=10
			Object.XPos-=32768
			Object.Value0--
			if Object.Value0==-256
				Object.State=1
				Object.Direction=FACING_LEFT
			endif
			if Player.YPos>Object.YPos
				TempValue0=Player.YPos
				TempValue0-=Object.YPos
				if TempValue0<4194304
					if Player.XPos>Object.XPos
						TempValue0=Player.XPos
						TempValue0-=Object.XPos
					else
						TempValue0=Object.XPos
						TempValue0-=Player.XPos
					endif
					if TempValue0<3145728
						Object.Value0=0
						Object.Frame=7
						Object.State=2
					endif
				endif
			endif
			break
		case 1
			Object.Frame++
			Object.Frame%=10
			Object.XPos+=32768
			Object.Value0++
			if Object.Value0==256
				Object.State=0
				Object.Direction=FACING_RIGHT
			endif
			if Player.YPos>Object.YPos
				TempValue0=Player.YPos
				TempValue0-=Object.YPos
				if TempValue0<4194304
					if Player.XPos>Object.XPos
						TempValue0=Player.XPos
						TempValue0-=Object.XPos
					else
						TempValue0=Object.XPos
						TempValue0-=Player.XPos
					endif
					if TempValue0<3145728
						Object.Value0=0
						Object.Frame=7
						Object.State=2
					endif
				endif
			endif
			break
		case 2
			Object.Value0++
			if Object.Value0==16
				Object.Value0=0
				Object.Frame++
				if Object.Frame==10
					Object.Frame=9
					Object.State=3
				endif
			endif
			break
		case 3
			Object.YPos+=393216
			ObjectTileCollision(0,0,14,0)
			if CheckResult==1
				Object.State=4
			endif
			break
		case 4
			break
		case 5
			if Object.OutOfBounds==1
				Object.State=0
				Object.Priority=0
			endif
			break

		endswitch
	endif
	CallFunction(StageSetup_CheckGoodFuture)
	if Object.OutOfBounds==1
		TempValue0=Object.XPos
		TempValue1=Object.YPos
		Object.XPos=Object.Value1
		Object.YPos=Object.Value2
		if Object.OutOfBounds==1
			Object.XPos=Object.Value1
			Object.YPos=Object.Value2
			Object.Direction=FACING_RIGHT
			Object.Value0=0
			Object.Frame=0
			Object.Priority=0
			Object.State=0
		else
			Object.XPos=TempValue0
			Object.YPos=TempValue1
		endif
	endif
endsub


sub ObjectPlayerInteraction
	if Object.State<5
		PlayerObjectCollision(C_TOUCH,-15,-10,15,10)
		if CheckResult==1
			CallFunction(PlayerObject_BadnikBreak)
		endif
	endif
endsub


sub ObjectDraw
	if Object.State<5
		if Object.PropertyValue==0
			if Object.State<2
				TempValue0=Object.Frame
				TempValue0>>=1
				DrawSpriteFX(TempValue0,FX_FLIP,Object.XPos,Object.YPos)
			else
				DrawSpriteFX(Object.Frame,FX_FLIP,Object.XPos,Object.YPos)
			endif
		else
			if Object.State<2
				TempValue0=Object.Frame
				TempValue0/=5
				TempValue0+=5
				DrawSpriteFX(TempValue0,FX_FLIP,Object.XPos,Object.YPos)
			else
				DrawSpriteFX(Object.Frame,FX_FLIP,Object.XPos,Object.YPos)
			endif
		endif
	endif
endsub


sub ObjectStartup
	LoadSpriteSheet("R1/Objects.gif")
	ArrayPos0=32
	while ArrayPos0<1056
		if Object[ArrayPos0].Type==TypeName[Mosqui]
			Object[ArrayPos0].Value1=Object[ArrayPos0].XPos
			Object[ArrayPos0].Value2=Object[ArrayPos0].YPos
		endif
		ArrayPos0++
	loop
	SpriteFrame(-16,-11,32,24,51,1)
	SpriteFrame(-16,-3,32,16,51,26)
	SpriteFrame(-16,-14,32,32,51,43)
	SpriteFrame(-6,-13,24,32,117,43)
	SpriteFrame(-10,-14,24,32,142,43)
	SpriteFrame(-16,-11,32,24,84,1)
	SpriteFrame(-16,-3,32,16,84,26)
	SpriteFrame(-16,-14,32,32,84,43)
	SpriteFrame(-6,-13,24,32,51,76)
	SpriteFrame(-10,-14,24,32,76,76)
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
